﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;

namespace DCT.CodeBox.LightLog.Utilities
{
    public static class FileUtility
    {
        public static string GetRealPath(string path)
        {
            path = path ?? "";
            if (path.StartsWith("~"))
            {
                path = HttpContext.Current.Server.MapPath(path);
            }
            else
            {
                path = Path.GetFullPath(path);
            }
            return path;
        }

        public static bool MakeSureFileExist(string filepath)
        {
            bool create = false;
            if (!File.Exists(filepath))
            {
                string folder = Path.GetDirectoryName(filepath);
                if (!Directory.Exists(folder))
                {
                    Directory.CreateDirectory(folder);
                }
                using (File.Create(filepath))
                {
                }
                create = true;
            }
            return create;
        }
    }
}
